export default {
  namespaced: true,
  state: {
    id: localStorage.getItem('user_id') || null,
    name: localStorage.getItem('user_name') || null,
    username: localStorage.getItem('user_username') || null,
    region: localStorage.getItem('user_region') || null,
    regionName: localStorage.getItem('user_regionName') || null,
    level: localStorage.getItem('user_level') || null,
    levelPath: localStorage.getItem('user_levelPath') || null,
    roles: ['sysadmin'],
    avatar:
      localStorage.getItem('user_avatar') ||
      'https://gw.alipayobjects.com/zos/rmsportal/WhxKECPNujWoWEFNdnJE.png'
  },
  mutations: {
    setId(state, id) {
      if (id) {
        localStorage.setItem('user_id', id);
      }
      state.id = id;
    },
    setName(state, name) {
      if (name) {
        localStorage.setItem('user_name', name);
      }
      state.name = name;
    },
    setUsername(state, username) {
      if (username) {
        localStorage.setItem('user_username', username);
      }
      state.username = username;
    },
    setRegion(state, region) {
      if (region) {
        localStorage.setItem('user_region', region);
      }
      state.region = region;
    },
    setRegionName(state, regionName) {
      if (regionName) {
        localStorage.setItem('user_regionName', regionName);
      }
      state.regionName = regionName;
    },
    setlevel(state, level) {
      if (level) {
        localStorage.setItem('user_level', level);
      }
      state.level = level;
    },
    setLevelPath(state, levelPath) {
      if (levelPath) {
        localStorage.setItem('user_levelPath', levelPath);
      }
      state.levelPath = levelPath;
    },
    setAvatar(state, avatar) {
      if (avatar) {
        localStorage.setItem('user_avatar', avatar);
      }
      state.avatar = avatar;
    }
  },
  actions: {
    setUserData({ commit }, { data }) {
      debugger;
      commit('setId', data.code);
      commit('setName', data.name);
      commit('setUsername', data.userName);
      commit('setRegion', data.region);
      commit('setRegionName', data.regionName);
      commit('setlevel', data.level);
      commit('setLevelPath', data.levelPath);
      commit('setAvatar', data.avatar);
    }
  }
};
